using System;
using System.Data;
using System.Web.UI;

namespace MyControls.DataSources.CompositeHierarchicalDataSource {
    /// <summary>
    /// A DataSourceView that takes a DataTable as its data source.
    /// </summary>
    public class TableDataSourceView : DataSourceView {
        private DataTable _dataTable;

        /// <summary>
        /// Constructs the view from a view name that must be in the owner's underlying dataset.
        /// </summary>
        /// <param name="owner">The <see cref="CompositeHierarchicalDataSource"/> that owns this view.</param>
        /// <param name="viewName">A view name (format is TabularSourceName:ViewName).</param>
        public TableDataSourceView(CompositeHierarchicalDataSource owner, string viewName)
            : base(owner, viewName) {
            _dataTable = owner.DataSet.Tables[viewName];
        }

        /// <summary>
        /// Returns the contents of the view.
        /// </summary>
        /// <param name="arguments">Not used.</param>
        /// <returns>The view.</returns>
        protected override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) {
            return _dataTable.DefaultView;
        }
    }
}
